#include "Projection_GPU.h"
#include "DimensionConvertor.h"
#include "ClusterHandler.h"
#include "Visualizer.h"

Projection_GPU::Projection_GPU(const int k, int width, int height, const cv::Mat intrinsic){
	this->k = k;
	this->width = width;
	this->height = height;
	//dim = new ApplyRigidTransform();
	dim = new DimensionConvertor();
	dim->setCameraParameters(intrinsic, width, height);
	initMemory();
	initNormalized3D();
}

Projection_GPU::~Projection_GPU(){
	cudaFree(PlaneFitted3D_Device);
	cudaFree(normal_device);
	cudaFree(Normalized3D_Device);
	delete dim;

	dim = 0;
}


void Projection_GPU::initMemory(){	
	cudaMalloc(&PlaneFitted3D_Device, width * height * sizeof(float3));
	cudaMalloc(&normal_device, k * sizeof(float4));
	cudaMalloc(&Normalized3D_Device, width * height * sizeof(float3));

}

void Projection_GPU::setClusterND(const float4* in){
	cudaMemcpy(normal_device, in, k * sizeof(float4), cudaMemcpyHostToDevice);
}

void Projection_GPU::setClusterMap(const int* labels){
	this->labels_device = labels;
}
void Projection_GPU::setInput3Dpoints(const float3* points3d_device){
	Points3D_Device = points3d_device;
}
float3*	Projection_GPU::GetPlaneFitted3D_Device()const{
	return PlaneFitted3D_Device;
}
